package leetcode.easy.q88;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Q {
    public static void main(String[] args) {
        int[] arr1 = new int[]{1, 2, 3, 4, 4, 4, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1};
        int[] arr2 = new int[]{1, 2, 3, 4, 4, 4, 4, 5};
        new Solution().merge(arr1, arr2.length, arr2, arr2.length);
        log.info("res:{}", arr1);
    }
}
//倒着来，填值
class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        //倒着来，填值
        int right = m + n - 1;
        for (int i = m - 1, j = n - 1; right >= 0; ) {
            if (j < 0) {
                break;
            } else if (i < 0) {
                nums1[right--] = nums2[j--];
            } else if (nums1[i] >= nums2[j]) {
                nums1[right--] = nums1[i--];
            } else {
                nums1[right--] = nums2[j--];
            }
        }
    }
}